<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/2
 * Time: 7:28
 */

include_once 'AlipayBase.php';
date_default_timezone_set("Asia/Shanghai");

class PayDemo1 extends AlipayBase {


    /*地址：https://docs.open.alipay.com/270/alipay.trade.page.pay
     * 统一请求需要的参数
     * 1.out_trade_no商户订单号 2.product_code 销售产品码 3.total_amount 订单总金额 4.subject 订单标题
     */

    public function __construct()
    {

    }
    public function payed()
    {
        //业务参数
        $post = $_POST;
        $post['out_trade_no'] = $_POST['orderid'];
        $post['product_code'] = 'FAST_INSTANT_TRADE_PAY';
        $post['total_amount']  = $_POST['price'];
        $post['subject'] = $_POST['productName'];

        //公共参数
        $parm = [
            'app_id'    =>  self::$appId,
            'method'    =>  'alipay.trade.page.pay',
            'format'    =>  'JSON',
            'return_url'=>  self::$returnUrl,
            'charset'   =>  'utf-8',
            'sign_type'   =>  'RSA2',
            'sign'   =>  '',
            'timestamp'   =>  date("Y-m-d H:i:s"),
            'version'   =>  '1.0',
            'notify_url'   =>  self::$notifyUrl,
            'biz_content'   =>''
        ];

        //拼接
        $post =json_encode($post);
        $parm['biz_content'] = $post;

        //拼接请求参数
        //去除 sign和sign_type 字典排序
        $dataUrl = $this->getSignStr($parm);

        $sign = $this->rsa2Sign($dataUrl);
        $parm['sign'] = $sign;


        $rediect = "https://openapi.alipaydev.com/gateway.do?".$this->getUrlStr($parm);
        //跳转支付宝
        echo $rediect;
        //header("localhost:".$rediect);










    }



}

//app_id=2016091000481004&amp;biz_content={&quot;orderid&quot;:&quot;12545&quot;,&quot;productName&quot;:&quot;\u6211\u7684\u6d4b\u8bd51235&quot;,&quot;price&quot;:&quot;20.01&quot;,&quot;out_trade_no&quot;:&quot;12545&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;,&quot;total_amount&quot;:&quot;20.01&quot;,&quot;subject&quot;:&quot;\u6211\u7684\u6d4b\u8bd51235&quot;}&amp;charset=utf-8&amp;format=JSON&amp;method=alipay.trade.page.pay&amp;notify_url=http://www.cc8w.com/alipay/notify.php&amp;return_url=http://www.cc8w.com/alipay/return.php&amp;sign_type=RSA2&amp;timestamp=2018-04-02 10:58:12&amp;version=1.0

$PayDemo = new PayDemo1();
$PayDemo->payed();